﻿@model IEnumerable

@{ Layout = "~/Views/Shared/_leftPanelLayout.cshtml";}
@section LeftTree
{
     
    @{
        Html.RenderPartial("DeptTreePartialView", new Webcar.Models.DeptTreeMode{ Action = "List", Controller = "Repair" ,ShowChild=false });
     }
}

    

@using (Html.BeginForm("SaveMaterial", "Repair", Html.ViewContext.RouteData.Values, FormMethod.Post))
{
<div id="mcontent" style="margin:5px 5px 5px 5px;width:850px"> 
   @Html.AntiForgeryToken()
    @Html.Hidden("repair_no",Html.ViewContext.RouteData.Values["id"])
    @Html.DevExpress().GridView(
    settings =>
    {
        settings.Name = "gridView";
        settings.InitDefaultPagerGridViewSettings();
        settings.EnableRowIndexColumn();
        settings.SettingsPager.Mode = GridViewPagerMode.ShowAllRecords;
        settings.EnableAlternatingRowColor();
        settings.KeyFieldName = "affair_no";;
        settings.Columns.Add("item_name", "部件名称");
        settings.Columns.Add("item_model", "部件规格");
        settings.Columns.Add("unit", "单位");
        settings.Columns.Add("nums", "数量");
        settings.Columns.Add("price", "单价");
        settings.Columns.Add("total_money", "小计");
        settings.TotalSummary.Add(DevExpress.Data.SummaryItemType.Sum, "nums").DisplayFormat = "n0";
        settings.TotalSummary.Add(DevExpress.Data.SummaryItemType.Sum, "total_money").DisplayFormat = "c";
        settings.Settings.ShowFooter = true;
        bool permisson = CurrentUser.CheckPermission(PermissionManager.编辑维修单);

        settings.Columns.Add(col =>
        {
            col.CellStyle.Paddings.Padding = 1;
            col.CellStyle.Paddings.PaddingLeft = 5;
            col.Caption = "";
            col.Width = 60;
            col.CellStyle.HorizontalAlign = HorizontalAlign.Center;

            col.SetDataItemTemplateContent(c =>
            {
                string key = DataBinder.Eval(c.DataItem, "affair_no").ToString();
                
                if (permisson)
                {
                    ViewContext.Writer.Write(
                        Html.ActionLink("[删除]", "DeleteMaterial", new { id = key }, new { onclick = "return confirm('是否要删除此维修材料?')" })
                    );
                }
                else
                {
                    ViewContext.Writer.Write("<a href='#' onclick = \"alert('你没有删除的权限。')\">[删除]</a>");
                }
            }
            );
        });
    }).Bind(Model).GetHtml()
    <hr />
    <table class="datalist" style="width:100%">
        <tr>
            <td>部件名称</td>
            <td>部件规格</td>
            <td>部件单位</td>
            <td>数量</td>
            <td>单价</td>
        </tr>
       <tr>
            <td>@Html.TextBox("edit_item_name", null, new { @style = "width: 95%;" })</td>
            <td>@Html.TextBox("edit_item_model", null, new { @style = "width: 95%;" })</td>
            <td>@Html.TextBox("edit_item_unit", null, new { @style = "width: 95%;" })</td>
            <td>@Html.TextBox("edit_item_nums", null, new { @style = "width: 95%;" })</td>
            <td>@Html.TextBox("edit_item_price", null, new { @style = "width: 95%;" })</td>
        </tr>

    </table>
    <div class="validation-errors">@ViewBag.ErrorMessage</div>
    <table style="width:100%">
        <tr>
            <td style="width:750px"></td>
            <td>
                @Html.DevExpress().Button(settings =>
                {
                    settings.Name = "Button1";
                    settings.Text = CurrentUser.CheckPermission(PermissionManager.编辑维修单) ? "增加" : "无权限";
                    settings.Enabled = CurrentUser.CheckPermission(PermissionManager.编辑维修单);
                    settings.UseSubmitBehavior = true;
                    settings.Width = 70;
                    settings.ControlStyle.CssClass = "button1";
                }).GetHtml()
            </td>
            <td>
                @Html.DevExpress().Button(settings =>
                {
                    settings.ControlStyle.CssClass = "button2";
                    settings.Name = "Button2";
                    settings.Text = "取消";
                    settings.Width = 70;
                    settings.ClientSideEvents.Click = "function(s, e){ location.href='" + @Url.Action("List", "Repair") + "' }";
                }).GetHtml()
            </td>
        </tr>

    </table>
    </div> 
}
           